#ifndef PARSER_H_
#define PARSER_H_

#include <string>
#include <vector>
#include <libxml++/libxml++.h>
#include <boost/shared_ptr.hpp>

#include "student.h"
#include "curriculum.h"
#include "coursesection.h"
#include "requirement.h"

/// Parse mechanism for stured curriculum, student and constraints information.
class Parser
{
	typedef const std::string& path;
public:

	//Destructor
    ~Parser(); // Doesn't need to be virtual, we don't intend to sub class.

    //Methods
    bool parse();
    
        
	// TODO: Add student file and prefix.
	void prefix(path prefix);
	std::string prefix() const;

	void student(path student);
	std::string student() const;
	
	void courses(path courses);
	std::string courses() const;

    static Parser* instance();

protected:
    bool doStudent();
    bool doCurriculum();
    bool doCourses();

private:
	static Parser * instance_;  // the one-and-only instance
    xmlpp::DomParser parser;

	// Starting to look like i want pimpl_;
	std::string _prefix;
    std::string _studentFilePath, _courseFilePath, _curriculumFilePath; //die ykw.
  
	xmlpp::Document* document;

    // c-tors and copy mechanisms are private to prohibit direct instantiation
    Parser();
    Parser(const Parser&);
    Parser& operator=(const Parser&);
    
	bool init();
	void doGroup(xmlpp::Element* element, std::string type, Curriculum& _curr );
	void doSection(xmlpp::Element* e, boost::shared_ptr<Course> course, boost::shared_ptr<CourseSection> parent);
	boost::posix_time::time_duration str_to_time(const std::string& time);
	boost::shared_ptr<Requirement> doRequirements(xmlpp::Element* node);
};

#endif
